package com.meilai.project.controller.web.business.workbench;

import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.business.workbench.SplitAnnualTargetDTO;
import com.meilai.project.service.business.workbench.SaleYearTargetService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 * 销售年度目标记录表 前端控制器
 * </p>
 *
 * @author haiYangXu
 * @since 2022-08-16
 */
@RestController
@RequestMapping("/api/web/saleYearTarget")
public class SaleYearTargetController {
    @Autowired
    private SaleYearTargetService service;

    @ApiOperation("添加年度目标")
    @PostMapping("/add")
    public CommonResult add(@RequestBody SplitAnnualTargetDTO dto) {
        return new CommonResult().success(service.add(dto));
    }

    @ApiOperation("补充年度目标")
    @PostMapping("/replenish")
    public CommonResult replenish(@RequestBody SplitAnnualTargetDTO dto) {
        return new CommonResult().success(service.replenish(dto));
    }

    @ApiOperation("分页列表")
    @GetMapping("/page")
    public CommonResult page(@RequestParam(name = "page", defaultValue = "1") Integer page,
                             @RequestParam(name = "page_size", defaultValue = "10") Integer page_size,
                             @RequestParam(name = "year", required = false) Integer year) {
        return new CommonResult().success(service.selectPage(page, page_size, year));
    }

    @ApiOperation("根据年ID查询详细信息")
    @GetMapping("/detail")
    public CommonResult detail(@RequestParam("year_id") Long year_id) {
        return new CommonResult().success(service.detail(year_id));
    }


    @ApiOperation("获取销售半年目标汇总")
    @GetMapping("/querySaleYearTargetSummary")
    public CommonResult querySaleYearTargetSummary(@RequestParam("year") Integer year,
                                                   @RequestParam("type") Integer type,
                                                   @RequestParam("user_id") Long user_id) {
        return new CommonResult().success(type != 3 ? service.querySaleYearTargetSummary(year, type, user_id) : service.querySaleAllYearTargetSummary(year, user_id));
    }

    @PostMapping("/calibration")
    @ApiOperation("校准")
    public CommonResult calibration(@RequestParam("year") Integer year,
                                    @RequestParam("type") Integer type,
                                    @RequestParam("user_id") Long user_id,
                                    @RequestParam("complete_amount") BigDecimal complete_amount) {
        return new CommonResult().success(service.calibration(year, type, user_id, complete_amount));
    }
}
